<template>
  <el-dialog title="添加分类" width="40%" :before-close="dialogClose" :visible.sync="show">
    <el-form ref="form" :model="item" label-width="80px">
        <el-form-item label="分类名称">
          <el-input v-model="item.name" class="select_input"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add">确 定</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: 'cateAdd',
  props:['show'],
  data() {
    return {
        item:{}
    }
  },
  created: function() {
  },
  methods: {
    dialogClose:function(){
      //this.show = false
      this.$emit("func",{'key':'cateAddShow','type':0})
    },
    add:function(){
      var that = this
      this.item.store_id = localStorage.getItem('store_id')
      if(!this.item.name){
        this.$message.error('分类名称不能为空!');
      }
      this.$post('goods/cateAdd',this.item).then((res) => {
          if(res.code == 1){
            that.$message.success(res.msg);
            that.$emit("func",{'key':'cateAddShow','type':0})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>